﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using NSEEOD_downloader.Tasks;

namespace NSEEOD_downloader
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
        }

        private void FormSettings_Load(object sender, EventArgs e)
        {
            Microsoft.Win32.RegistryKey AppKeys = Application.UserAppDataRegistry;
            txtDest.Text = Utils.GetString(AppKeys.GetValue("DATA_DIR"));
            txtNSEEOD.Text = Utils.GetString(AppKeys.GetValue(NSEEODTask.SETTINGS_PARSELINK));
            txtNSEFOEOD.Text = Utils.GetString(AppKeys.GetValue(NSEFOEODTask.SETTINGS_PARSELINK));

            if (txtNSEEOD.Text.Length < 2)
            {
                txtNSEEOD.Text = @"http://www.nseindia.com/content/historical/EQUITIES/[yyyy]/[MMM]/cm[dd][MMM][yyyy]bhav.csv";
            }
            if (txtNSEFOEOD.Text.Length < 2)
            {
                txtNSEFOEOD.Text = @"http://www.nseindia.com/content/historical/DERIVATIVES/[yyyy]/[MMM]/fo[dd][MMM][yyyy]bhav.csv";
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Microsoft.Win32.RegistryKey AppKeys = Application.UserAppDataRegistry;
            AppKeys.SetValue("DATA_DIR", txtDest.Text);
            AppKeys.SetValue(NSEEODTask.SETTINGS_PARSELINK, txtNSEEOD.Text);
            AppKeys.SetValue(NSEFOEODTask.SETTINGS_PARSELINK, txtNSEFOEOD.Text);
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browse = new FolderBrowserDialog();
            browse.SelectedPath = txtDest.Text;
            if (DialogResult.OK == browse.ShowDialog(this))
            {
                txtDest.Text = browse.SelectedPath;
            }            
        }            
    }
}
